package com.example.demo.netty;

import compaser.proto.utils.BuffCompase;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.timeout.IdleStateHandler;
import lombok.extern.log4j.Log4j2;


/**
 * Created by frank on 15/9/23.
 * netty框架 ，加入一些解析Handler
 */
@Log4j2
public class MattressSocketServerInitialzer extends ChannelInitializer<SocketChannel> {

    /**
     *
     */
    private static final MattressSocketServerHandler SERVER_HANDLER = new MattressSocketServerHandler(new BuffCompase());

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new ByteArrayDecoder());
        pipeline.addLast(new IdleStateHandler(90, 0, 0));
        pipeline.addLast(SERVER_HANDLER);
    }
}
